package main

import (
	"fmt"
	"net"
	"sync"
	"time"
)

//端口扫描器
var w sync.WaitGroup

func doScan(port int) {
	defer w.Done()
	s := fmt.Sprintf("h5java.cn:%d", port)
	_, err := net.Dial("tcp", s)
	if err != nil {
		//fmt.Printf("%d关闭了\n", port)
		return
	}
	fmt.Printf("%d打开了\n", port)
}

//并发扫描端口
func scan() {
	for i := 3478; i <= 3478; i++ {
		w.Add(1)
		go doScan(i)
	}
}

func main50() {
	s := time.Now().Unix()
	scan()
	w.Wait()
	e := time.Now().Unix()
	fmt.Printf("扫描完成,耗时:%d s\n", e-s)
}
